package com.TexasHoldem.ServerData;

import io.netty.channel.Channel;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.swing.text.TabExpander;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService;
import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.ActDataResponse;
import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.BoardUpdatedResponse;
import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.CommunityCardsResponse;
import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.HandResponse;
import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.PlayerActedDataResponse;
import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.PlayerData;
import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.PlayerEnterResponse;
import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.PlayerLeaveResponse;
import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.Response;
import com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.ShowCardsDataResponse;
import com.TexasHoldem.ServerData.Quest.PlayPokerQuest;
import com.TexasHoldem.ServerData.Quest.PlayerLoginQuest;
import com.TexasHoldem.ServerData.Quest.PlayerOnlineAwardQuest;
import com.TexasHoldem.ServerData.Quest.PokerQuest;
import com.TexasHoldem.ServerData.Quest.PokerQuestRule;
import com.TexasHoldem.ServerData.Quest.QuestData;
import com.TexasHoldem.core.Card;
import com.TexasHoldem.core.Client;
import com.TexasHoldem.core.Player;
import com.TexasHoldem.core.Pot;
import com.TexasHoldem.core.TableConfig;
import com.TexasHoldem.core.TableType;
import com.TexasHoldem.core.actions.Action;
import com.TexasHoldem.core.actions.BetAction;
import com.TexasHoldem.core.actions.BigBlindAction;
import com.TexasHoldem.core.actions.RaiseAction;
import com.TexasHoldem.xSocket.data.CommonConstants;
import com.TexasHoldem.xSocket.engine.SocketHandler;
import com.google.protobuf.BlockingRpcChannel;
import com.google.protobuf.RpcController;
import com.google.protobuf.ServiceException;
import com.googlecode.protobuf.socketrpc.RpcChannels;
import com.googlecode.protobuf.socketrpc.SocketRpcController;



/**
 * @author su wei
 * Player 代表扑克桌子上玩家，PokerPlayer 代表是扑克玩家身份,player都是通过Pokerplayer接口下发信息
 */
public class PokerPlayer implements Client{
	
	
	public long id;
	
	public String name;
	
	public long YXB = 0;
	
	public List<PokerQuest> curpokerqust;
	
	public List<PokerQuest> getCurpokerqust()
	{
		return curpokerqust;
	}

	public void setCurpokerqust(List<PokerQuest> curpokerqust)
	{
		this.curpokerqust = curpokerqust;
	}

	public long getYXB()
	{
		return YXB;
	}

	public void setYXB(long yXB)
	{
		YXB = yXB;
	}
	public PokerPlayerStatistics statistics = new PokerPlayerStatistics();
	
	
	//  保存当前玩家 在哪些桌子上面玩牌,支持多桌子打牌
	public Map<Integer,Player> curplaytable = new HashMap<Integer, Player>();
	
	public Map<Integer, Player> getCurplaytable() {
		return curplaytable;
	}
	
	public PokerPlayerStatistics getStatistics()
	{
		return statistics;
	}

	public PokerPlayer(long id) {
		super();
		this.id = id;
		
		
		
	}
	public void Init()
	{
		curpokerqust = new ArrayList<PokerQuest>();
		
		curpokerqust.add(new PlayerLoginQuest());
		curpokerqust.add(new PlayerOnlineAwardQuest());
		curpokerqust.add(new PlayPokerQuest());
		
		for(PokerQuest pokerquest:curpokerqust)
		{
			pokerquest.OnInit(this);
		}
	}
	public void QuestProcess()
	{
		for(PokerQuest pokerquest:curpokerqust)
		{
			pokerquest.OnQuestProcess();
		}
	}
	public void setStatistics(PokerPlayerStatistics statistics)
	{
		this.statistics = statistics;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	private Channel clientchannel;
	
	public Channel getClientchannel() {
		return clientchannel;
	}

	public void setClientchannel(Channel clientchannel) {
		this.clientchannel = clientchannel;
	}
	private SocketHandler sockethandle;
	
	public SocketHandler getSockethandle() {
		return sockethandle;
	}
	public void setSockethandle(SocketHandler sockethandle) {
		this.sockethandle = sockethandle;
	}
	
	
	@Override
	public void messageReceived(String message) {
		// TODO Auto-generated method stub

		if(this.getClientchannel() != null)
		{
			 TexasHoldemService.NotifyMsg.Builder notifymsg = TexasHoldemService.NotifyMsg.newBuilder();

	         notifymsg.setMsg(message);
	         
	         BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	         
	         com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	         
	         
	         RpcController controller = new SocketRpcController();
	         try 
	         {
	        	 com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.NotifyMsgResponse Response = service.notifyMessage(controller, notifymsg.build());
	        	 
			}
	        catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	        	e.printStackTrace();
			}
		}
		
	}
	@Override
	public void joinedTable(TableType type, int bigBlind, List<Player> players) {
		// TODO Auto-generated method stub
		
	}
	// 通知牌桌里面的玩家有新牌局开始
	@Override
	public void handStarted(Player dealer) {
		// TODO Auto-generated method stub

	}
	// 更新当前活动玩家
	@Override
	public void actorRotated(int tableid,Player actor,int position) {
		// TODO Auto-generated method stub

		if(this.getClientchannel() != null)
		{
			TexasHoldemService.ActorRotateData.Builder actorrotae = TexasHoldemService.ActorRotateData.newBuilder();

			 actorrotae.setPlayerid(actor.getClient().getId());
			 actorrotae.setPosition(position);
			 actorrotae.setTableid(tableid);
	         
	         BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	         
	         com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	         
	         
	         RpcController controller = new SocketRpcController();
	         try 
	         {
	        	 com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.ActorRotatedResponse Response = service.actorRotated(controller, actorrotae.build());
	        	 
			}
	        catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	        	e.printStackTrace();
			}
		}
	}
	@Override
	public void playerUpdated(int tableid,Player player) {
		// TODO Auto-generated method stub

		if(this.getClientchannel() != null)
		{
			TexasHoldemService.playerUpdateData.Builder playerupdata = TexasHoldemService.playerUpdateData.newBuilder();

			playerupdata.setPlayerid(player.getClient().getId());
			playerupdata.setCash(player.getCash());
			playerupdata.setName(player.getName());
			playerupdata.setTableid(tableid);
			playerupdata.setBet(player.getBet());
			 
	        
	        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	        
	        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	        
	        
	        RpcController controller = new SocketRpcController();
	        try 
	        {
	       	 com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.PlayerUpdatedResponse Response = service.playerUpdated(controller, playerupdata.build());
	       	 
			}
	       catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	       	e.printStackTrace();
			}
		}
		
	}
	@Override
	public void boardUpdated(int tableid,List<Card> cards, int bet, List<Pot> pots) {
		// TODO Auto-generated method stub

		
		if(this.getClientchannel() != null)
		{
			TexasHoldemService.BoardUpdatedData.Builder boardupdate = TexasHoldemService.BoardUpdatedData.newBuilder();

			boardupdate.setBet(bet);
			for(Pot p:pots)
				boardupdate.addPot(TexasHoldemService.Potdata.newBuilder().setPot(p.getValue()));
			
			boardupdate.setTableid(tableid);
			for(Card c:cards)
			{
				boardupdate.addCards(TexasHoldemService.Carddata.newBuilder().setCard(c.toString()).build());
			}
			 
	        
	        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	        
	        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	        
	        
	        RpcController controller = new SocketRpcController();
	        try 
	        {
	       	 BoardUpdatedResponse Response = service.boardUpdated(controller, boardupdate.build());
	       	 
			}
	        catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	        	e.printStackTrace();
			}
		}
	}
	//通知其他玩家,有玩家已经执行动作
	@Override
	public void playerActed(int tableid,Player actedplayer) {
		// TODO Auto-generated method stub

		if(this.getClientchannel() != null)
		{
			TexasHoldemService.PlayerActedData.Builder playeracteddata = TexasHoldemService.PlayerActedData.newBuilder();

			playeracteddata.setActionname(actedplayer.getAction().getName());
			playeracteddata.setBet(actedplayer.getBet());
			playeracteddata.setPlayerid(actedplayer.getClient().getId());
			playeracteddata.setName(actedplayer.getName());
			playeracteddata.setTableid(tableid);
			playeracteddata.setCash(actedplayer.getCash());
	        
	        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	        
	        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	        
	        
	        RpcController controller = new SocketRpcController();
	        try 
	        {
	       	 	PlayerActedDataResponse Response = service.playerActed(controller, playeracteddata.build());
	       	 
			}
	        catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	        	e.printStackTrace();
			}
		}
		
		
	}
	@Override
	public boolean act(int tableid,int minBet, int currentBet, Set<Action> allowedActions) {
		// TODO Auto-generated method stub

		if(this.getClientchannel() != null && this.IsPlayerOnline())
		{
			TexasHoldemService.ActData.Builder actdata = TexasHoldemService.ActData.newBuilder();

			actdata.setCurrentbet(currentBet);
			actdata.setMinbet(minBet);
			actdata.setTableid(tableid);
			for(Action a:allowedActions)
				actdata.addActions(TexasHoldemService.AllowAction.newBuilder().setActionname(a.getName()).build());
	        
	        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	        
	        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	        
	        
	        RpcController controller = new SocketRpcController();
	        try 
	        {
	       	 	ActDataResponse Response = service.act(controller, actdata.build());
	       	 
			}
	        catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	        	e.printStackTrace();
			}
			return true;
			
		}
		return false;
	}

	@Override
	public void playerEnterTable(int tableid,Player enterplayer) {
		// TODO Auto-generated method stub

		
		if(this.getClientchannel() != null)
		{
			TexasHoldemService.PlayerEnterData.Builder enterdata = TexasHoldemService.PlayerEnterData.newBuilder();

			enterdata.setCash(enterplayer.getCash());
			enterdata.setId(enterplayer.getClient().getId());
			enterdata.setName(enterplayer.getName());
			enterdata.setTableid(tableid);
			enterdata.setPos(enterplayer.getPos());
	        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	        
	        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	        
	        
	        RpcController controller = new SocketRpcController();
	        try 
	        {
	       	 	PlayerEnterResponse Response = service.playerEnterTable(controller, enterdata.build());
	       	 
			}
	        catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	        	e.printStackTrace();
			}
			
		}
	}

	@Override
	public void playerLeaveTable(int tableid,Player leaveplayer) {
		// TODO Auto-generated method stub

		
		if(this.getClientchannel() != null)
		{
			TexasHoldemService.PlayerLeaveData.Builder data = TexasHoldemService.PlayerLeaveData.newBuilder();

			
			data.setId(leaveplayer.getClient().getId());
			data.setTableid(tableid);
	        
	        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	        
	        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	        
	        
	        RpcController controller = new SocketRpcController();
	        try 
	        {
	       	 	PlayerLeaveResponse Response = service.playerLeaveTable(controller, data.build());
	       	 
			}
	        catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	        	e.printStackTrace();
			}
			
		}
	}

	@Override
	public void dealCommunityCardsUpdate(int tableid,List<Card> lists) {
		// TODO Auto-generated method stub
		
		if(this.getClientchannel() != null)
		{
			TexasHoldemService.CommunityCards.Builder data = TexasHoldemService.CommunityCards.newBuilder();

			
			
			data.setTableid(tableid);
			for(Card c:lists)
			{
				data.addCards(TexasHoldemService.Carddata.newBuilder().setCard(c.toString()).build());
			}
	        
	        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	        
	        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	        
	        
	        RpcController controller = new SocketRpcController();
	        try 
	        {
	       	 	CommunityCardsResponse Response = service.dealCommunityCardsUpdate(controller, data.build());
	       	 
			}
	        catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	        	e.printStackTrace();
			}
			
		}
	}

	@Override
	public void ShowCards(int tableid,Player showplayer) {
		// TODO Auto-generated method stub
		if(this.getClientchannel() != null)
		{
			TexasHoldemService.ShowCardsData.Builder data = TexasHoldemService.ShowCardsData.newBuilder();

			
			
			data.setTableid(tableid);
			for(Card c:showplayer.getCards())
			{
				data.addCards(TexasHoldemService.Carddata.newBuilder().setCard(c.toString()).build());
			}
	        data.setId(showplayer.getClient().getId());
	        data.setName(showplayer.getName());
	        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	        
	        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	        
	        
	        RpcController controller = new SocketRpcController();
	        try 
	        {
	       	 	ShowCardsDataResponse Response = service.showCards(controller, data.build());
	       	 
			}
	        catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	        	e.printStackTrace();
			}
			
		}
	}

	@Override
	public void restart(int tableid) {
		// TODO Auto-generated method stub
		JSONObject j = new JSONObject();
		j.put("name", this.getCurplaytable().get(tableid).getName());
		j.put("reset", 1);
		this.sockethandle.sendResponse(CommonConstants.SERVER_RESET, j.toString());
	}

	@Override
	public void HandUpdate(int tableid,Player playerhandupdate) {
		// TODO Auto-generated method stub
		if(this.sockethandle != null)
		{
			JSONObject j = new JSONObject();
			String cardsinfo = "";
			for(Card c:playerhandupdate.getCards())
			{
				cardsinfo = cardsinfo + c.toString() + ",";
			}
			j.put("cards", cardsinfo);
			j.put("id", playerhandupdate.getClient().getId());
			j.put("tableid", tableid);
			this.sockethandle.sendResponse(CommonConstants.SERVER_HANDUPDATE, j.toString());
		}
		
		if(this.getClientchannel() != null)
		{
			TexasHoldemService.HandData.Builder data = TexasHoldemService.HandData.newBuilder();

			
			
			data.setTableid(tableid);
			for(Card c:playerhandupdate.getCards())
			{
				data.addCards(TexasHoldemService.Carddata.newBuilder().setCard(c.toString()).build());
			}
	        data.setId(playerhandupdate.getClient().getId());
	        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
	        
	        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
	        
	        
	        RpcController controller = new SocketRpcController();
	        try 
	        {
	       	 	HandResponse Response = service.handUpdate(controller, data.build());
	       	 
			}
	        catch (ServiceException e) 
			{
					// TODO Auto-generated catch block
	        	e.printStackTrace();
			}
			
		}
	}

	public void LoginInfo(Channel c)
	{
		TexasHoldemService.LoginSucessData.Builder data = TexasHoldemService.LoginSucessData.newBuilder();

		data.setPlayerid(this.id);
		data.setName(this.name);
		data.setCash(5000);
        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(c);
        
        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
        
        
        RpcController controller = new SocketRpcController();
        try 
        {
       	 	Response Response = service.loginReturn(controller, data.build());
       	 
		}
        catch (ServiceException e) 
		{
				// TODO Auto-generated catch block
        	e.printStackTrace();
		}
	}
	@Override
	public Long getId() {
		// TODO Auto-generated method stub
		return this.id;
	}

	@Override
	public void PlayersUpdate(int tableid,Collection<Player> l) {
		// TODO Auto-generated method stub
		TexasHoldemService.PlayersList.Builder data = TexasHoldemService.PlayersList.newBuilder();

		for(Player p:l)
		{
			PlayerData.Builder pd =PlayerData.newBuilder();
			pd.setCash(p.getCash());
			pd.setPlayerid(p.getClient().getId());
			pd.setName(p.getName());
			pd.setTableid(tableid);
			pd.setPos(p.getPos());
			data.addList(pd);
			
		}
        
        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
        
        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
        
        
        RpcController controller = new SocketRpcController();
        try 
        {
       	 	Response Response = service.playersUpdate(controller, data.build());
       	 
		}
        catch (ServiceException e) 
		{
				// TODO Auto-generated catch block
        	e.printStackTrace();
		}
	}

	@Override
	public void PlayersWinUpdate(int tableid, List<Player> l) {
		// TODO Auto-generated method stub
		
		TexasHoldemService.PlayersList.Builder data = TexasHoldemService.PlayersList.newBuilder();

		for(Player p:l)
		{
			PlayerData.Builder pd = PlayerData.newBuilder();
			pd.setCash(p.getCash());
			pd.setPlayerid(p.getClient().getId());
			pd.setName(p.getName());
			pd.setTableid(tableid);
			data.addList(pd);
			
		}
        
        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
        
        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
        
        
        RpcController controller = new SocketRpcController();
        try 
        {
       	 	Response Response = service.playersWinUpdate(controller, data.build());
       	 
		}
        catch (ServiceException e) 
		{
				// TODO Auto-generated catch block
        	e.printStackTrace();
		}
	}

	@Override
	public void PlayersDealer(int tableid, Player dealer) {
		// TODO Auto-generated method stub
		TexasHoldemService.PlayerData.Builder data = TexasHoldemService.PlayerData.newBuilder();

		data.setTableid(tableid);
		data.setCash(dealer.getCash());
		data.setPlayerid(dealer.getClient().getId());
		data.setName(dealer.getName());
		data.setPos(dealer.getPos());
        
        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
        
        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
        
        
        RpcController controller = new SocketRpcController();
        try 
        {
       	 	Response Response = service.playersDealer(controller, data.build());
       	 
		}
        catch (ServiceException e) 
		{
				// TODO Auto-generated catch block
        	e.printStackTrace();
		}
	}

	@Override
	public void TableRoomUpdate(TableConfig config) {
		// TODO Auto-generated method stub
		
		TexasHoldemService.TableRoomInfo.Builder data = TexasHoldemService.TableRoomInfo.newBuilder();

		data.setTableid(config.getId());
		data.setRoomName(config.getName());
		data.setBigBlind(config.getBigBlind());
		data.setRoomIp("");
		data.setRoomPort("");
		data.setBettimeout(config.getBetTimeOut());
        
        BlockingRpcChannel blockchannel = RpcChannels.newBlockingRpcChannel(this.getClientchannel());
        
        com.TexasHoldem.RpcInterface.rpc.TexasHoldemService.TexasHoldemClient.BlockingInterface service = TexasHoldemService.TexasHoldemClient.newBlockingStub(blockchannel);
        
        
        RpcController controller = new SocketRpcController();
        try 
        {
       	 	Response Response = service.tableRoomInfoUpdate(controller, data.build());
       	 
		}
        catch (ServiceException e) 
		{
				// TODO Auto-generated catch block
        	e.printStackTrace();
		}
		
	}

	@Override
	public boolean IsPlayerOnline() {
		// TODO Auto-generated method stub
		if(this.getClientchannel().isActive() || this.getClientchannel().isOpen())
			return true;
		else
			return false;
	}
	
	


	@Override
	public void AddPlayerInTable(Player addplayer,int tableId)
	{
		// TODO Auto-generated method stub
		this.curplaytable.put(tableId, addplayer);
	}


	@Override
	public void DelPlayerInTable(int tableId)
	{
		// TODO Auto-generated method stub
		this.curplaytable.remove(tableId);
	}

	@Override
	public void OnDisconnect(Player player)
	{
		// TODO Auto-generated method stub
		for(PokerQuest pokerquest:curpokerqust)
		{
			pokerquest.OnSave();
		}
		
	}

	@Override
	public String toString()
	{
		// TODO Auto-generated method stub
		return this.getId() + "_" + this.getName() + "_" + this.getClientchannel().toString();
	}
	
	
}
